/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Functions;

import java.text.SimpleDateFormat;
import java.util.Calendar;

/**
 *
 * @author Airwyn
 */
public class SystemTime {
    
    private static Calendar calendar; 
    private static SimpleDateFormat dateFormat; 
    private static SimpleDateFormat timeFormat; 
    private static String currentDate; 
    private static String currentTime;
    
    
    public static String WebDateFormat = "EEEEEEEEEE, MMMMMMMMM dd yyyy";
    public static String WebTimeFormat = "h:mm:ss a";
    
    public static String MySQLDateFormat = "yyyy-MM-dd";
    public static String MySQLTimeFormat = "HH:mm:ss";
    
    
    //Get the current system Time
    public String getCurrentTime(){
        calendar = Calendar.getInstance();
        timeFormat = new SimpleDateFormat(WebTimeFormat);
        currentTime = timeFormat.format(calendar.getTime());
        return currentTime;
        
    }
    
    //Get the current system Time in MySQL Format
    public String getCurrentTimeMySQLFormat(){
        calendar = Calendar.getInstance();
        timeFormat = new SimpleDateFormat(MySQLTimeFormat);
        currentTime = timeFormat.format(calendar.getTime());
        return currentTime;
        
    }
    
    
    //Get the current system date in MySQL Format
    public String getCurrentDateMySQLFormat(){
        calendar = Calendar.getInstance();
        dateFormat = new SimpleDateFormat(MySQLDateFormat);
        try{
            currentDate = dateFormat.format(calendar.getTime());
        }
        catch(Exception ex){
            currentDate = dateFormat.format(calendar.getTime());
        }   
        return currentDate;
        
    }
    
    
    
    //Get the current system date
    public String getCurrentDate(){
        calendar = Calendar.getInstance();
        dateFormat = new SimpleDateFormat(WebDateFormat);
        try{
            currentDate = dateFormat.format(calendar.getTime());
        }
        catch(Exception ex){
            currentDate = dateFormat.format(calendar.getTime());
        }   
        return currentDate;
        
    }
    
    
    
    public boolean isWithinCurrentDate(Calendar calendar){
        Calendar currentCalendar = Calendar.getInstance();
        SimpleDateFormat monthFormat = new SimpleDateFormat("MM");
        SimpleDateFormat dayFormat = new SimpleDateFormat("dd");
        SimpleDateFormat yearFormat = new SimpleDateFormat("yyyy");
        int currentMonth = Integer.parseInt(monthFormat.format(currentCalendar.getTime()));
        int currentDay = Integer.parseInt(dayFormat.format(currentCalendar.getTime()));
        int currentYear = Integer.parseInt(yearFormat.format(currentCalendar.getTime()));
        int month = calendar.get(Calendar.MONTH)+1;
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        int year = calendar.get(Calendar.YEAR);
        if(year>currentYear){
            return false;
        }
        else{
            if(month>currentMonth){
                return false;
            }
            else{
                if(day>currentDay){
                    return false;
                }
                else{
                    return true;
                }
            }
        }
    }
    
    
    @SuppressWarnings("CallToThreadDumpStack")
    public void sleep(int n){
        try{
            Thread.sleep(n);
        }catch(Exception ex){
            ex.printStackTrace();
        }
    }
}
